package com.lianwei.hospital.Service.Impl;

import com.lianwei.hospital.Service.OpdInfoService;
import com.lianwei.hospital.mapper.OpdInfoMapper;
import com.lianwei.hospital.module.entity.IllInfo;
import com.lianwei.hospital.module.entity.OpdInfo;
import com.lianwei.hospital.module.vo.OpdVO;
import com.lianwei.hospital.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("OpdInfoService")
public class OpdInfoImpl implements OpdInfoService {
    @Autowired
    OpdInfoMapper opdInfoMapper;

    @Override
    public OpdInfo selectByPrimaryKey(String uId) throws Exception {
        return opdInfoMapper.selectByPrimaryKey(uId);
    }

    @Override
    public boolean insert(OpdInfo opdInfo) throws Exception {
        return opdInfoMapper.insert(opdInfo)>0;
    }

    @Override
    public List<OpdInfo> selectAll() throws Exception {
        return opdInfoMapper.selectAll();
    }

    @Override
    public boolean deleteByPrimaryKey(String uId) throws Exception {
        return opdInfoMapper.deleteByPrimaryKey(uId)>0;
    }

    @Override
    public boolean updateByPrimaryKey(OpdInfo opdInfo) throws Exception {
        return opdInfoMapper.updateByPrimaryKey(opdInfo)>0;
    }

    @Override
    public PageUtil<OpdInfo> findPage(OpdVO query) throws Exception {
        /*
         * 1.获取总记录数
         * 2.如果总记录数 > 0 查询数据
         *  将数据封装到PageUtil
         * 否则，返回null
         */
        int count=opdInfoMapper.countBySelectActive(query);
        if (count>0){
            List<OpdInfo> data=opdInfoMapper.selectListBySelectActive(query);
            return new PageUtil<>(query.getCurrentPage(),query.getPageSize(),count,data);
        }
        return null;
    }
}
